import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;


public class DBConnect {
	
	Connection conn = null;
	
	public DBConnect(String dbName, String userName, String password){
		
	    try 
	    {
	    	String myDriver = "com.mysql.jdbc.Driver";
	        String myUrl = "jdbc:mysql://localhost/";
	        Class.forName(myDriver);
	        conn = DriverManager.getConnection(myUrl+dbName, userName, password);
	    	System.out.println("Connected to the database");
	    }
	    catch (Exception e) 
	    {
	      e.printStackTrace();
	    }
	}
	
	public void insert(String subiect, String predicat, String data, String start, String stop) 
	{
		try {
			Statement statement = conn.createStatement();
			if(stop == "null")
				statement.executeUpdate("INSERT INTO sdsl  " + "VALUES (0, '"+subiect+"', '" + predicat+"', '" + data + "' , '"+start+"',"+null+")");
			else
				statement.executeUpdate("INSERT INTO sdsl  " + "VALUES (0, '"+subiect+"', '" + predicat+"', '" + data + "' , '"+start+"','"+stop+"')");
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		 
	}
}
